package com.guoliang.cmsService.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoliang.cmsService.entity.CrmBanner;
import com.guoliang.cmsService.service.CrmBannerService;
import com.guoliang.commonUtils.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.COMM_FAILURE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author ：Leo
 * @date ：Created in 2023/1/25 22:14
 * @description：
 */
@RestController
@RequestMapping("/cmsService/adminBanner")
public class BannerAdminController {
    @Autowired
    CrmBannerService bannerService;
    @Autowired
    RedisTemplate redisTemplate;
    @ApiOperation("分页查询Banner")
    @GetMapping("getBannerPage/{page}/{limit}")
    public CommonResult getBannerPage(@PathVariable("page")Integer page,@PathVariable("limit")Integer limit){
        Page<CrmBanner> bannerPage=new Page<>(page,limit);
        bannerService.page(bannerPage);
        return CommonResult.ok().data("total",bannerPage.getTotal()).data("items",bannerPage.getRecords());
    }
    @ApiOperation("添加Banner")
    @PostMapping
    public CommonResult addBanner(@RequestBody CrmBanner banner){
        //删除redis缓存
        redisTemplate.delete("banner::selectIndexList");
        bannerService.save(banner);
        return CommonResult.ok();
    }
    @ApiOperation("修改Banner")
    @PutMapping
    public CommonResult updateBanner(@RequestBody CrmBanner banner){
        bannerService.updateById(banner);
        return CommonResult.ok();
    }
    @ApiOperation("删除banner")
    @DeleteMapping("{id}")
    public CommonResult deleteBanner(@PathVariable String id){
        //删除redis缓存
        redisTemplate.delete("banner::selectIndexList");
        bannerService.removeById(id);
        return CommonResult.ok();
    }
}
